package com.repair.repairSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.repair.common.annotation.Log;
import com.repair.common.core.controller.BaseController;
import com.repair.common.core.domain.AjaxResult;
import com.repair.common.enums.BusinessType;
import com.repair.repairSys.domain.RepairOrders;
import com.repair.repairSys.service.IRepairOrdersService;
import com.repair.common.utils.poi.ExcelUtil;
import com.repair.common.core.page.TableDataInfo;

/**
 * 维修订单Controller
 * 
 * @author repair
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/repairSys/orders")
public class RepairOrdersController extends BaseController
{
    @Autowired
    private IRepairOrdersService repairOrdersService;

    /**
     * 查询维修订单列表
     */
    @PreAuthorize("@ss.hasPermi('repairSys:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairOrders repairOrders)
    {
        startPage();
        List<RepairOrders> list = repairOrdersService.selectRepairOrdersList(repairOrders);
        return getDataTable(list);
    }

    /**
     * 导出维修订单列表
     */
    @PreAuthorize("@ss.hasPermi('repairSys:orders:export')")
    @Log(title = "维修订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairOrders repairOrders)
    {
        List<RepairOrders> list = repairOrdersService.selectRepairOrdersList(repairOrders);
        ExcelUtil<RepairOrders> util = new ExcelUtil<RepairOrders>(RepairOrders.class);
        util.exportExcel(response, list, "维修订单数据");
    }

    /**
     * 获取维修订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('repairSys:orders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(repairOrdersService.selectRepairOrdersById(id));
    }

    /**
     * 新增维修订单
     */
    @PreAuthorize("@ss.hasPermi('repairSys:orders:add')")
    @Log(title = "维修订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairOrders repairOrders)
    {
        return toAjax(repairOrdersService.insertRepairOrders(repairOrders));
    }

    /**
     * 修改维修订单
     */
    @PreAuthorize("@ss.hasPermi('repairSys:orders:edit')")
    @Log(title = "维修订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairOrders repairOrders)
    {
        return toAjax(repairOrdersService.updateRepairOrders(repairOrders));
    }

    /**
     * 删除维修订单
     */
    @PreAuthorize("@ss.hasPermi('repairSys:orders:remove')")
    @Log(title = "维修订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(repairOrdersService.deleteRepairOrdersByIds(ids));
    }
}
